/**
 * Copyright 2015 Software innovation and R & D center. All rights reserved.
 * File Name: SystemException.java
 * Encoding UTF-8
 * Version: 0.0.1
 * History:	2015年1月17日
 */
package com.imeth.base.model;

import java.io.Serializable;

/**
 * 分页参数对象
 * @author: weihuang.peng
 * @version Revision: 0.0.1
 * @Date: 2015年3月17日
 * update Description : 去除访问最后一页的限制
 * update Date : 2015年3月17日
 */
public class Paging implements Serializable {

	private static final long serialVersionUID = 7468721784590351690L;

	private int records;//总记录数
	
	private int pageSize = 10;//页面条数
	
	private int pageCount;//页面总数
	
	private int currentPage = 1;//当前页面
	
	public Paging() {
	
	}

	public Paging(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = (currentPage < 1 ? 1 : currentPage);
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = Math.abs(pageSize);
	}

	public int getRecords() {
		return records;
	}

	public void setRecords(int records) {
		if (records == 0) {
			//pageCount = 1;
			return;
		}
			
		this.records = records;
		if (pageSize > 0) {

			pageCount = ((int) Math.ceil((records - 1) / pageSize) + 1);
			
			if (currentPage < 1) {
				currentPage = 1;
			}
		}
	}

	public int getFirstPage() {
		return 1;
	}

	public int getPrePage() {
		return currentPage - 1 >= 1 ? currentPage - 1 : 1;
	}

	public int getNextPage() {
		return currentPage + 1 > pageCount ? pageCount : currentPage + 1;
	}

	public boolean isFirst() {
		return currentPage == 1;
	}

	public boolean isLast() {
		return currentPage == pageCount;
	}

	public int getStartRow() {
		return (currentPage - 1) * pageSize;
	}
}